﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace StartBrowser
{
    class Program
    {
        static void Main(string[] args)
        {
            string browserFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NFinal.Browser.exe");
            Start(browserFileName, 800,600,"豫便利启动测试","http://www.yubianli.com");
        }
        /// <summary>
        /// 启动浏览器
        /// </summary>
        /// <param name="browserFileName">浏览器路径</param>
        /// <param name="width">浏览器初始化宽度</param>
        /// <param name="height">浏览器初始化高度</param>
        /// <param name="title">浏览器标题</param>
        /// <param name="url">浏览器初始url</param>
        public static void Start(string browserFileName, int width, int height, string title, string url)
        {
            if (File.Exists(browserFileName))
            { 
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = browserFileName;
                p.StartInfo.UseShellExecute = false;    //是否使用操作系统shell启动
                p.StartInfo.RedirectStandardInput = false;//接受来自调用程序的输入信息
                p.StartInfo.RedirectStandardOutput = false;//由调用程序获取输出信息
                p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
                p.StartInfo.CreateNoWindow = true;//不显示程序窗口
                p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                p.StartInfo.Arguments = $"-w {width} -h {height} -t {title} -u {url}";
                p.Start();//启动程序
                p.Close();
            }
        }
    }
}
